﻿--MonitorClient-----------------
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MonitorClient]'))
DROP TABLE [dbo].[MonitorClient]
GO

CREATE TABLE [dbo].[MonitorClient](
	[Key] [uniqueidentifier] NOT NULL DEFAULT NEWID(),
	[Name] [nvarchar](100) NOT NULL,
	[Description] [nvarchar](200) NULL,
	[CreatedStamp] [datetime] NOT NULL,
	[LastUpdatedStamp] [datetime] NOT NULL,
	[LastSyncStamp] [datetime] NULL,
 CONSTRAINT [PK_MonitorClient] PRIMARY KEY CLUSTERED 
([Key] ASC)ON [PRIMARY])

GO

--ClientHeartbeat-----------------
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ClientHeartbeat]'))
DROP TABLE [dbo].[ClientHeartbeat]
GO

CREATE TABLE [dbo].[ClientHeartbeat](
	[Key] [uniqueidentifier] NOT NULL DEFAULT NEWID(),
	[ClientKey] [uniqueidentifier] NOT NULL,
	[CreatedStamp] [datetime] NOT NULL,
 CONSTRAINT [PK_ClientHeartbeat] PRIMARY KEY CLUSTERED 
([Key] ASC)ON [PRIMARY])

GO

--MonitorTask-----
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MonitorTask]'))
DROP TABLE [dbo].[MonitorTask]
GO

CREATE TABLE [dbo].[MonitorTask](
	[Key] [uniqueidentifier] NOT NULL DEFAULT NEWID(),
	[Name] [nvarchar](100) NOT NULL,
	[AssignedToClientKey] [uniqueidentifier] NOT NULL,
	[ExecutionType] [int] NOT NULL,
	[Options] [int] NOT NULL DEFAULT 0,
	[DomainScopeCode] [varchar](20) NOT NULL,
	[ThirdPartyIdentity] [varchar](150) NOT NULL,
	[IsNightOperationOnly]	[bit] NOT NULL DEFAULT 0,
	[IsDisabled] [bit] NOT NULL DEFAULT 0,
	[CreatedStamp] [datetime] NOT NULL,
	[LastUpdatedStamp] [datetime] NOT NULL,
	[LastExecutionStamp] [datetime] NULL,
 CONSTRAINT [PK_MonitorTask] PRIMARY KEY CLUSTERED 
([Key] ASC)ON [PRIMARY])
GO

--TaskExecutionRecord-----
/*
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TaskExecutionRecord]'))
DROP TABLE [dbo].[TaskExecutionRecord]
GO

CREATE TABLE [dbo].[TaskExecutionRecord](
	[Key] [uniqueidentifier] NOT NULL DEFAULT NEWID(),
	[TaskKey] [uniqueidentifier] NOT NULL,
	[IsSuccess]	[bit] NOT NULL,
	[Exception] [nvarchar](MAX) NULL,	
	[CreatedStamp] [datetime] NOT NULL,
 CONSTRAINT [PK_TaskExecutionRecord] PRIMARY KEY CLUSTERED 
([Key] ASC)ON [PRIMARY])
GO
*/